<template>
  <div class="detialHeader">
    <nav class="shop-nav" :style="{backgroundImage: `url(${infoList.bgImg})`}">
      <span @click="$router.back()"><van-icon name="arrow-left" /></span>
    </nav>
    <div class="box" @click="showDesc">
      <van-image
        width="66"
        height="66"
        :src="infoList.avatar"
      />
      <p class="title">{{infoList.name}}</p>
      <div class="des">
        <span>{{infoList.score}}</span>
        <span>月售{{infoList.sellCount}}单</span>
        <span>{{infoList.description}}</span>
        <span>约{{infoList.deliveryTime}}分钟</span>
        <span>距离{{infoList.distance}}</span>
      </div>
      <div class="yh" v-if="infoList.supports"  @click.stop="handleClick">
        <div class="yh-left">
          <span>{{infoList.supports[0].name}}</span>
          <span>{{infoList.supports[0].content}}</span>
        </div>
        <div class="yh-right">
          {{infoList.supports.length}}个优惠 ▼
        </div>
      </div>
    </div>
    <van-action-sheet v-model="flag" title="优惠">
      <ul>
        <li
        v-for="(item, index) in infoList.supports"
        :key="index"
        >
        <span class="name">{{item.name}}</span>
        <span>{{item.content}}</span>
        </li>
      </ul>
    </van-action-sheet>
  </div>
</template>

<script>
import { getShopInfo } from '@/api/detial'
export default {
  name: 'DetialHeader',
  data () {
    return {
      infoList: [],
      flag: false
    }
  },
  async created () {
    const info = await getShopInfo()
    // console.log(info.data.data)
    this.infoList = info.data.data
  },
  methods: {
    showDesc () {
      this.$dialog.alert({
        title: `${this.infoList.name}`,
        message: `${this.infoList.bulletin}`
      }).then(() => {
      // on close
      })
    },
    handleClick () {
      this.flag = !this.flag
    }
  }
}
</script>

<style lang="less" scoped>
.shop-nav{
  width: 100%;
  height: 50px;
  line-height: 50px;
  color: #eee;
  font-size: 28px;
  span{
    margin-left: 20px;
    display: inline-block;
    margin-top: 7px;
  }
}
/deep/.van-image{
  margin: -27px 155px;
  border: 1px solid #eee;
}
.box{
  color: #333;
  .title{
    margin-top: 24px;
    font-weight: 700;
    text-align: center;
    font-size: 22px;
  }
  .des{
    text-align: center;
    font-size: 12px;
    span{
      margin-left: 8px;
    }
  }
  .yh{
    width: 315px;
    height: 25px;
    border: 1px solid #eee;
    margin: 4px auto;
    font-size: 12px;
    line-height: 25px;
    .yh-left{
      width: 250px;
      white-space:nowrap;
      overflow:hidden;
      text-overflow:ellipsis;
      float: left;
      span:nth-child(1){
        margin: 0 10px;
        background-color: green;
        color: #fff;
      }
    }
    .yh-right{
      float: right;
      margin-right: 6px;
    }
  }
}
  ul {
    font-size: 12px;
    li{
      margin-top: 6px;
    }
    .name{
      background-color: green;
      color: #fff;
      margin: 6px;
    }
  }
</style>
